package cn.starrysky108.simpleerp.article.service.impl;

import cn.starrysky108.simpleerp.article.entity.Article;
import cn.starrysky108.simpleerp.article.mapper.ArticleMapper;
import cn.starrysky108.simpleerp.article.service.ArticleService;
import cn.starrysky108.simpleerp.user.service.OnlineDeviceInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 文章 服务实现类
 * </p>
 *
 * @author Carl Lee
 */
@Service
@CacheConfig(cacheNames = "article")
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> implements ArticleService {
    private OnlineDeviceInfoService deviceInfoService;

    @Override
    @Cacheable(key = "'article'+#id")
    public Article getArticle(Long id) {
        return getById(id);
    }

    @Override
    @CacheEvict(key = "'article'+#id")
    public void deleted(Long id) {
        removeById(id);
    }
    @Override
    @CachePut(key = "'article'+#entity.id")
    public Article add(Article entity) {
        saveOrUpdate(entity);
        return entity;
    }
    @Autowired
    public void setDeviceInfoService(OnlineDeviceInfoService deviceInfoService) {
        this.deviceInfoService = deviceInfoService;
    }

}
